﻿using UnityEngine;
using System.Collections;

public class CLife : MonoBehaviour
{
    // Use this for initialization
	public void StartGame()
    {
        ResetLife();
    }

    public void ResetLife()
    {
        m_nCurLife = m_cDefaultLife;
        Debug.Log("ResetLife.m_nCurLife : " + m_nCurLife.ToString());
        _UpdateLife();
    }

    public void DecreasLife( int nLife )
    {
        m_nCurLife -= nLife;
        if (0 == m_nCurLife)
            m_nCurLife = 0;
        _UpdateLife();
    }

    private void _UpdateLife()
    {
        for (int nIndex = 0; nIndex < m_HeartList.Length; nIndex++)
        {
            if (null != m_HeartList[nIndex] && true == m_HeartList[nIndex].active )
            {
                bool bActive = (m_nCurLife > nIndex ? true : false);
                m_HeartList[nIndex].active = bActive;
                if (false == bActive)
                {
                    Vector3 vPos = m_HeartList[nIndex].transform.position;
                    CGlobalMgr.Instance.EffectMgr.Touch(CEffectMgr.E_TYPE.LIFEDESTROY, vPos);
                }
                Debug.Log("m_HeartList[nIndex].active : " + m_HeartList[nIndex].active.ToString());
            }
        }
    }

    public int m_cDefaultLife = 0;
    public Sprite[] m_HeartList;
    private int m_nCurLife = 0;

    public int Life
    {
        get { return m_nCurLife; }
        set { m_nCurLife = value; }
    }
}
